#/usr/bin/env python
#-*-coding:utf-8-*-
"""
抽象工厂模式
"""
from abc import ABCMeta , abstractmethod

class AbstractProductA(object):
	"""
	抽象产品，可能拥有多种实现
	"""
	def __init__(self,name):
		self.name = name

	def __str__(self):
		return "ProductA:%s" % self.name


class ConcreteProductA1(AbstractProductA):
	pass

class ConcreteProductA2(AbstractProductA):
	pass

class AbstractProductB(object):
	"""
	抽象产品，可能拥有多种实现
	"""
	
	def __init__(self,name):
		self.name = name 

	def __str__(self):
		return "ProductB: %s" % self.name

class ConcreteProductB1(AbstractProductB):
	pass

class ConcreteProductB2(AbstractProductB):
	pass

class AbstractFactory(object):
	"""
	抽象工厂接口，包含所有产品创建的抽象方法
	"""
	__metaclass__ = ABCMeta

	@abstractmethod
	def create_product_a(self):
		pass

	@abstractmethod
	def create_product_b(self):
		pass

class ConcreteFactory1(AbstractFactory):
	"""
	具体工厂，创建具有特定实现的产品对象
	"""
	def create_product_a(self):
		return ConcreteProductA1("PA1")

	def create_product_b(self):
		return ConcreteProductB1("PB1")

class ConcreteFactory2(AbstractFactory):
	def create_product_a(self):
		return ConcreteProductA2("PA2")

	def create_product_b(self):
		return ConcreteProductB2("PB2")

if __name__ == '__main__':
	factory = ConcreteFactory2()

	product_a = factory.create_product_a()
        product_b = factory.create_product_b()
        
	factory1 = ConcreteFactory1()
	product1_a = factory1.create_product_a()
	product1_b = factory1.create_product_b()
	
	print product1_a
	print product1_b

	print product_b
	print product_a

